from flask import Flask , request
from flask import render_template
from research import reserch4letters

# 服务端的中央登记中心
# 1.URL：*URL的相对路径（终结点）*request的methods【get】【post】
# 2.view function：视图函数，*模板渲染【HTML+CSS】*，处理数据
# 3.return：返回到templates文件夹中对应的HTML文件


app = Flask(__name__)

# 1. 登记路由： route
@app.route('/',methods=['GET','POST']) # / 根路径，首页, 相对路径
# 2. 视图函数，返回值为页面的显示信息，文本txt，html，json等
def hello():
    return render_template('hello.html')

# 练习：尝试写一个界面 路由为 /index， 视图函数返回的内容为 <h1>这是首页</h1>
@app.route('/index',methods=['GET','POST'])
def index():
    return render_template('index.html')

@app.route('/result',methods=['POST'])
def result():
    # 用户输入的信息是在 request中的
    first_name = request.form['firstname']
    last_name = request.form['lastname']
    full_name = first_name.title() + ' ' + last_name.title()

    py_word = request.form['word']
    py_vowels = request.form['vowels']
    py_found = reserch4letters(py_vowels, py_word)

    return render_template('result.html',
                           fullname=full_name,
                           found = py_found)

@app.route('/goods',methods=['GET','POST'])
def goods():
      return render_template('goods.html')


if __name__ == '__main__':
    app.run(host='127.0.0.1',port=5000,debug=True)
